/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef VETH_INTERNAL_H
#define VETH_INTERNAL_H

#include "Platform_Types.h"
#include "eth_general_types.h"

#define vETH_FRAMEHEADER_LENGTH (14U)
#define vETH_FRAMECHKSUM_LENGTH (4U)
#define vETH_MACADDRESS_LEN (6U)
#define vETH_FRAME_DESTADDR_POS (0U)
#define vETH_FRAME_SRCADDR_POS (6U)
#define vETH_FRAME_TYPE_POS_MSB (12U)
#define vETH_FRAME_TYPE_POS_LSB (13U)
#define vETH_SHIFT_8BIT (8U)
#define vETH_FRAME_PAYLOAD_POS (14U)
#define vETH_BYTE_MASK (0xFFU)

typedef struct {
    uint8 buff_status; /* used or not used */
    uint8 tx_confirm_req; /* txconfirm request */
    uint8 frame_tx_initiated; /* Tx data has been put in */
    uint8 frame_tx_sent;
    uint16 length;
} veth_tx_buf_tables_type;

typedef struct {
    uint8 buff_status; /* used or not used */
    uint8 frame_rx_initiated; /* Rx data has been put in */
    uint16 length;
} veth_rx_buf_tables_type;

typedef struct {
    veth_tx_buf_tables_type *eth_tx_buff_table_ptr;
    veth_rx_buf_tables_type *eth_rx_buff_table_ptr;
    uint8 *eth_rx_buffer_ptr;
    uint8 *eth_tx_buffer_ptr;
} veth_buff_type;

typedef struct {
    uint32 crc_error_frame_counter;
    uint32 under_size_frame_counter;
    uint32 over_size_frame_counter;
    uint32 alignment_error_frame_counter;
    uint32 single_collision_counter;
    uint32 multiple_collision_counter;
    uint32 late_collision_counter;
} veth_statistics_counter_type;

typedef struct {
    eth_mode_type eth_controller_mode;
    eth_mode_type preveth_controller_mode;
    eth_state_type veth_init_status;
    uint8 curr_tx_idx;
    uint8 confirm_tx_buf_idx;
    uint8 curr_rx_idx;
    uint8 eth_unicast_mac_address[6];
} veth_run_time_opertn_data_type;

typedef struct {
    veth_run_time_opertn_data_type eth_run_time_opertn_data;
    veth_statistics_counter_type eth_statistics_counters;
    veth_buff_type *eth_buff_ptr;
} veth_ctrl_status_type;

void veth_print(int priority, const char *fmt, ...);

#endif
